<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="layout" content="bocMain"/>
    <title>进件作业系统</title>
</head>

<body>

<header class="header-title">人脸识别</header>
<g:form action="contactApprove" class="myform">
    <input type="hidden" id="id" name="id" value="${this?.opportunity?.id}">

    <div class="photoFrame">
        <div class="photo-item">
            <i class="weui-icon-success weui-icon_msg icon-info"></i>
            <h5 style="margin-top: 1rem">匹配成功!</h5>
            <h5 style="margin-top: .5rem;font-size: 1.3rem">匹配相似度${params?.score?.toDouble() * 100}%</h5>
        </div>
    </div>

    <div class="face-info">
        <p style="text-align: center">地点：<span id="addressText"></span></p>

        <p style="text-align: center">时间：${new Date().format("yyyy-MM-dd")}</p>
    </div>

    <input type="hidden" value="" id="locationData">
    
    <div class="bigBtn">
        <button type="submit" class="weui-btn weui-btn_primary" id="submit">下一步</button>
    </div>

</g:form>

<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.7&key=309fec051f4a8306ea2d8f5710c7c7c2&plugin=AMap.Geolocation,AMap.Geocoder"></script>


<script>

    $(function () {

        getLocation();

        function getLocation() {
            var lnglat;
            var map = new AMap.Map('container', {
                resizeEnable: true
            });

            map.plugin('AMap.Geolocation',function () {
                var geolocation = new AMap.Geolocation({
                    // 是否使用高精度定位，默认：true
                    enableHighAccuracy: true,
                    // 设置定位超时时间，默认：无穷大
                    timeout: 10000,
                    // 定位按钮的停靠位置的偏移量，默认：Pixel(10, 20)
                    buttonOffset: new AMap.Pixel(10, 20),
                    //  定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
                    zoomToAccuracy: true,
                    //  定位按钮的排放位置,  RB表示右下
                    buttonPosition: 'RB'
                })

                geolocation.getCurrentPosition()
                AMap.event.addListener(geolocation, 'complete', onComplete)
                AMap.event.addListener(geolocation, 'error', onError)

                function onComplete(data) {
                    // data是具体的定位信息
                    var locationData = {
                        longitude: data.position.lng,
                        latitude: data.position.lat
                    };
                    $("#locationData").val(locationData.longitude + "," + locationData.latitude);
                    AMap.plugin('AMap.Geocoder', function () {
                        var geocoder = new AMap.Geocoder();
                        lnglat = $("#locationData").val().split(',');
                        geocoder.getAddress(lnglat, function (status, result) {
                            if (status === 'complete' && result.regeocode) {
                                var address = result.regeocode.formattedAddress;
                                $("#addressText").text(address);
                            } else {
                                alert(result.message);
                            }
                        })
                    })
                }
                function onError(result) {
                    // 定位出错
                    alert(result.message);
                }
            })
        }
    });
</script>

</body>
</html>
